package day0228;


public class Demo04 {

    private static String out = "out";

    private int a = 1;

    /*
        内部类：
            成员内部类
            局部内部类： 方法中声明的类
                匿名类： 没有类名
     */
    public class InnerClass {
        private int a = 2;

        private String inner = "inner";
        private static String in = "inner";

        public InnerClass() {
        }

        public void show() {
            int a = 3;
            System.out.println(a);
            System.out.println(this.a);
            System.out.println(Demo04.this.a); // 外部类 Demo04.super
            System.out.println("innerClass " + out);
        }
    }

    public void print() {
        InnerClass innerClass = new InnerClass();
        innerClass.inner = "aaa";

        InnerClass.in = "222";


        final int a = 1;

        // 成员内部类不能写 访问修饰符
        class A {
            public void show(){
                // 调用的外部变量需要是 final 或有效的 final
                System.out.println(a);
            }
        }

        A a1 = new A(); // local class

    }

    // 嵌套内部类
    protected static class StaticClass {

        public void show() {
            System.out.println("innerClass " + out);
        }
    }
}

class Demo05 {

    public static void main(String[] args) {
        // 内部类的实例
        Demo04 outer = new Demo04(); // 先创建外部类对象
        // new OuterClass().new InnerClass();
        Demo04.InnerClass innerClass = outer.new InnerClass();

        innerClass.show();

        Demo04.StaticClass staticInnerClass = new Demo04.StaticClass();
    }

}
